/*
 * @Descripttion:
 * @version:
 * @Author: ChenXiang
 * @Date: 2021-07-10 12:02:05
 * @LastEditors: ChenXiang
 * @LastEditTime: 2021-09-07 09:28:21
 */
import React, {
  useState,
  useEffect,
  FC,
  ButtonHTMLAttributes,
  AnchorHTMLAttributes,
  useRef,

} from "react";
import classNames from "classnames";
import utils from "@/common/utils";
import "./button.scss";

export type ButtonSize = "lg" | "sm";
export type ButtonType = "primary" | "default" | "danger" | "link";

interface BaseButtonProps {
  className?: string;
  /**设置 Button 的禁用 */
  disabled?: boolean;
  /**设置 Button 的尺寸 */
  size?: ButtonSize;
  /**设置 Button 的类型 */
  btnType?: ButtonType;
  children: React.ReactNode;
  href?: string;
}
type NativeButtonProps = BaseButtonProps & ButtonHTMLAttributes<HTMLElement>;
type AnchorButtonProps = BaseButtonProps & AnchorHTMLAttributes<HTMLElement>;
export type ButtonProps = Partial<NativeButtonProps & AnchorButtonProps>;
/**
 * 页面中最常用的的按钮元素，适合于完成特定的交互
 * ### 引用方法
 *
 * ~~~js
 * import { Button } from 'vikingship'
 * ~~~
 */

const min = 200

export const Count: FC<ButtonProps> = (props) => {
  const { btnType, className, disabled, size, children, href, ...restProps } =
    props;
  const trackRef = useRef([]);
  const [value, setValue] = useState('');
  const [valueOld, setValueOld] = useState('');

  useEffect(() => {

  }, []);

  return (
    <input type="text" value={value} onChange={(e) => {
      const val = e.target.value;

      if (val === '0' || val === '') {
        setValue('')
        return
      }
      //为true不通过
      const isFail = [
        utils.regular.isChinese.test(val),
        utils.regular.isAlpha.test(val),
        utils.regular.isFh.test(val),
      ].includes(true);
      console.log('isFail', isFail);

      if (isFail === false) {
        console.log('trackRef', trackRef.current);
        if (Number(val) < min) {
          console.log('q1');
          setValue(val);
        }
        // if (trackRef.current.length === 0) {
        //   setValue(val);
        // }
        if (utils.number.numberRange(val, 1000, min)) {
          console.log('q2');
          setValue(val);

        }
      }
    }} />
  )

};

Count.defaultProps = {
  disabled: false,
  btnType: "default",
};

export default Count;
